<?php

namespace app\common\model\account;

use app\common\model\CommonModel;



class AccountModel extends CommonModel{

    protected  $name = 'account';

    protected  $pk   = 'account_id';



    public function manageShop()

    {

        return $this->hasMany(ShopAccountModel::class,'account_id','account_id');

    }

    public function shopAccount()

    {

        return $this->hasOne(ShopAccountModel::class,'account_id','account_id');

    }


    public function createShop()

    {

        return $this->hasMany(ShopAccountModel::class,'account_id','account_id');

    }



    public function getLastLoginTimeFormatAttr($value,$data)

    {

        return $data['last_login_time'] > 0 ? date('Y-m-d H:i:s',$data['last_login_time']) : '-';

    }

    public function getnumber(){
        $number=rand(0,9).rand(0,9).rand(0,9);
        $one=$this->where(['number'=>$number])->find();
        if(!empty($one)){
            return $this->getnumber();
        }
        return $number;
    }

}

